package com.wolfheader.wolfgame.entity;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * Entity - 游戏总记录
 * 
 * @author 8615 Team
 * @version 1.0
 */
@Entity
@Table(name = "t_gameRecord")
@SequenceGenerator(name = "sequenceGenerator", sequenceName = "game_gameRecord_sequence")
public class GameRecordEntity extends BaseEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3000422208196308593L;

	/**
	 * 名次
	 */
	private Integer rank;
	
	/***
	 * 助力次数
	 */
	private Integer assCount;

	/***
	 * 助力分数
	 */
	private Integer assScore;

	/***
	 * 自己分数
	 */
	private Integer score;

	/**
	 * 总分： 助力 + 自己
	 */
	private Integer totalScore;

	/***
	 * 游戏id
	 */
	private String gameid;

	/**
	 * 玩家信息
	 */
	private GamePlayerEntity gamePlayer;

	/**
	 * 记录创建时间
	 */
	private Long recordDateTime;
	
	public GameRecordEntity() {
		super();
	}

	public Long getRecordDateTime() {
		return recordDateTime;
	}

	public void setRecordDateTime(Long recordDateTime) {
		this.recordDateTime = recordDateTime;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	public GamePlayerEntity getGamePlayer() {
		return gamePlayer;
	}

	public void setGamePlayer(GamePlayerEntity gamePlayer) {
		this.gamePlayer = gamePlayer;
	}

	public String getGameid() {
		return gameid;
	}

	public void setGameid(String gameid) {
		this.gameid = gameid;
	}
	
	@JsonProperty("rank")
	public Integer getRank() {
		return rank;
	}

	public void setRank(Integer rank) {
		this.rank = rank;
	}

	@JsonProperty("ass_num")
	public Integer getAssCount() {
		return assCount;
	}

	public void setAssCount(Integer assCount) {
		this.assCount = assCount;
	}

	@JsonProperty
	public Integer getAssScore() {
		return assScore;
	}

	public void setAssScore(Integer assScore) {
		this.assScore = assScore;
	}

	@JsonProperty
	public Integer getScore() {
		return score;
	}

	public void setScore(Integer score) {
		this.score = score;
	}

	/**
	 * 持久化前处理
	 */
	@PrePersist
	public void prePersist() {
		setAssCount(0);
		setAssScore(0);
		setScore(0);
		setUpdateDate(new Date());
		setRecordDateTime(new Date().getTime());
	}

	@JsonProperty("total_score")
	public Integer getTotalScore() {
		return totalScore;
	}

	public void setTotalScore(Integer totalScore) {
		this.totalScore = totalScore;
	}

	/**
	 * 获取玩家昵称
	 * 
	 * @return 创建时间
	 */
	@JsonProperty("nickname")
	@Transient
	public String getNickNameAsJson() {
		return getGamePlayer().getNickname();
	}
}
